//
// Created by user on 2022/3/7.
//
#include <vector>
#include <algorithm>
using namespace std;
//转换为窗口中1最多或者0最少的时候
int minSwaps(vector<int>& data){
    //计算有多少个1
    int onesCnt = 0;
    for (int i = 0; i < data.size(); ++i) {
        if(data[i]==1)onesCnt++;
    }
    //窗口大小为1的个数
    int windowsSize = onesCnt;
    int left = 0;
    int right = 0;
    //存储每个窗口中0的数量
    int windowZeroCnt = 0;
    int minZeroCnt = INT_MAX;
    while (right<data.size()){
        if(data[right]==0)windowZeroCnt++;
        if(right-left+1==windowsSize){
            minZeroCnt = min(windowZeroCnt, minZeroCnt);
            if(data[left]==0)windowZeroCnt--;
            left++;
        }
        right++;
    }
    return minZeroCnt==INT_MAX?0:minZeroCnt;
}